package cn.ycc1.web.config;

import cn.ycc1.web.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author ycc
 * @date 2024/9/16
 * 可以扩展springmvc的功能
 */
// @EnableWebMvc 全面接管了springmvc 所有的自动配置都失效 不推荐
@Configuration // 配置类
public class MyMvcConfig extends WebMvcConfigurerAdapter {
    public void addViewControllers(org.springframework.web.servlet.config.annotation.ViewControllerRegistry registry) {
        registry.addViewController("/ycc1").setViewName("success");
    }

    @Bean
    public WebMvcConfigurerAdapter myWebMvcConfigurerAdapter() {
        WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {
            @Override
            public void addViewControllers(org.springframework.web.servlet.config.annotation.ViewControllerRegistry registry) {
                registry.addViewController("/ycc2").setViewName("success");
            }
        };
        return adapter;
    }

    @Bean // 配置自己的国际化解析器
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }
}
